package com.lemurian.entity;
// Generated Jan 13, 2012 10:56:58 AM by Hibernate Tools 3.2.1.GA


import java.io.Serializable;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Type;

import com.lemurian.entity.utils.DefaultPersistence;

/**
 *
 * Menu generated by aditya
 *
 */

@Entity
@Table(name="tb_menu")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@BatchSize(size=10000)
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Menu extends DefaultPersistence implements Serializable {

	private static final long serialVersionUID = -7858691045100305852L;

    @Column(name = "name", length = 128)
    private String name;

    @Column(name = "description", length = 128)
    private String description;

    @Column(name = "url", length = 100)
    private String url;

    @ManyToOne
	@JoinColumn(name="parent_id",nullable=true)
	@Fetch(FetchMode.JOIN)
	private Menu parent;

    @Column(length=1,name="is_view",nullable=false)
	@Type(type="true_false")
    private boolean show;

    @Column(length=1,name="is_parent",nullable=true)
	@Type(type="true_false")
    private boolean showParent;

	@Transient
	private int length;
    @Transient
    private int childSum;

    @OneToMany(mappedBy="parent", fetch=FetchType.LAZY)
	//@Fetch(FetchMode.SELECT)
    private Set<Menu> childs;
    
    public Menu() {
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getUrl() {
        return this.url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * @return the parent
     */
    public Menu getParent() {
        return parent;
    }

    /**
     * @param parent the parent to set
     */
    public void setParent(Menu parent) {
        this.parent = parent;
    }

    /**
     * @return the show
     */
    public boolean isShow() {
        return show;
    }

    /**
     * @param show the show to set
     */
    public void setShow(boolean show) {
        this.show = show;
    }

    /**
     * @return the showParent
     */
    public boolean isShowParent() {
        return showParent;
    }

    /**
     * @param showParent the showParent to set
     */
    public void setShowParent(boolean showParent) {
        this.showParent = showParent;
    }

    /**
     * @return the length
     */
    public int getLength() {
        return length;
    }

    /**
     * @param length the length to set
     */
    public void setLength(int length) {
        this.length = length;
    }

    /**
     * @return the childSum
     */
    public int getChildSum() {
        return childSum;
    }

    /**
     * @param childSum the childSum to set
     */
    public void setChildSum(int childSum) {
        this.childSum = childSum;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Set<Menu> getChilds() {
        return childs;
    }

    public void setChilds(Set<Menu> childs) {
        this.childs = childs;
    }
    
    public String getParentName() {
		if (getParent()!=null) {
			if (getParent().getParent()!=null) return getParent().getParent().getName() + " :: " + getParent().getName()+" :: " + getName();
			else return getParent().getName()+" :: " + getName();
		} else return getName();
	}
}